package com.xjj.service.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.xjj.entity.Parent;
import com.xjj.entity.ParentAdvice;
import com.xjj.entity.ResponseEntity;
import com.xjj.service.exception.VertifyException;
import com.xjj.service.service.ParentAdviceService;
import com.xjj.util.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description 家长阅读情况表
 * @Author zhangjin
 * @Date 2022/10/28 10:44
 */
@RestController
@RequestMapping("/advice/api")
public class ParentAdviceController {
    @Autowired
    private ParentAdviceService service;

    @PostMapping("/addReadNum")
    public ResponseEntity addParentAdvice(@RequestBody ParentAdvice parentAdvice, HttpServletRequest request) throws JsonProcessingException {
        String token = request.getHeader("token");
        Parent parent = JwtUtil.getParent(token);
        parentAdvice.setParentId(parent.getId());
        if (parentAdvice.getParentId()==0 || parentAdvice.getAdviceId()==0){
            throw new VertifyException("参数不合法");
        }
        return ResponseEntity.SUCCESS("操作成功",service.addAdviceReader(parentAdvice));
    }
}
